﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HA.Data;

using System.Collections.ObjectModel;





namespace HA.ModFlow.Controls
{
    public class PCCoverageAtrributeTable:PCBase
    {

        public PCCoverageAtrributeTable(Coverage coverage)
        {


         

           


            this._coverage = coverage;

            this._isShowLayerRange = this._coverage.Setup.ScTypes[MAPSCType.LAYERRANGE];

            //this._features = new ObservableCollection<FeatureObject>();

            //foreach (FeatureObject item in this._coverage.Featureobjects)
            //{
              

            //    this._features.Add((FeatureObject)item.Clone());

            //}


            this._features = new ObservableCollection<PCFeatureObject>();

            List<FeatureObject> cloneFO = this._coverage.GetFeatureObjectClone();

            foreach (FeatureObject item in cloneFO)
            {
                PCFeatureObject pc = new PCFeatureObject((FeatureObject)item, this);

                this._features.Add(pc);

            }





         

            this._ptBCTypes = new List<MAPSCType>();
            this._lnBCTypes = new List<MAPSCType>();
            this._ndBCTypes = new List<MAPSCType>();

            this._polyBCTypes = new List<MAPSCType>();

           



            





            List<MAPSCType> apts=BCHelper.GetAllPtSCTypes();

            foreach (MAPSCType pt in apts)
            {

                if (this._coverage.Setup.ScTypes[pt]==true)
                {
                    this._ptBCTypes.Add(pt);
                    
                }

                
            }


            List<MAPSCType> alns = BCHelper.GetAllLnSCTypes();

            foreach (MAPSCType ln in alns)
            {
                if (this._coverage.Setup.ScTypes[ln] == true)
                {
                    this._lnBCTypes.Add(ln);

                }

            }



            List<MAPSCType> apys = BCHelper.GetAllPolygonSCTypes();

            foreach (MAPSCType py in apys)
            {
                if (this._coverage.Setup.ScTypes[py]==true)
                {
                    this.PolyBCTypes.Add(py);
                    
                }
            }





            this._ptBCTypes.Add(MAPSCType.NONE);
            this._lnBCTypes.Add(MAPSCType.NONE);

            
            this._polyBCTypes.Add(MAPSCType.NONE);




            ///初始化可选类型

            this._allFOTypes = new List<FeatureObjectType>();

            this._allFOTypes.Add(FeatureObjectType.POINT);
            this._allFOTypes.Add(FeatureObjectType.LINE);
            this._allFOTypes.Add(FeatureObjectType.NODE);
            //this._allFOTypes.Add(FeatureObjectType.LINEGROUP);
            this._allFOTypes.Add(FeatureObjectType.POLYGON);
           





            //初始化约束选项

            if (this._coverage.Featureobjects.Count>0)
	        {
                    FeatureObject fo=this._coverage.Featureobjects[0];

                    if (fo is PointFO)
                    {
                        _currentFOType = FeatureObjectType.POINT;
                        
                    }

                    if (fo is LineFO)
                    {
                        _currentFOType = FeatureObjectType.LINE;
                        
                    }

                    if (fo is NodeFO)
                    {
                        _currentFOType = FeatureObjectType.NODE;
                        
                    }

                    if (fo is PolygonFO)
                    {
                        _currentFOType = FeatureObjectType.POLYGON;
                        
                    }









		 
	        }

            //this._currentFilterBCType=;

          


 
        }


        Coverage _coverage;

        public Coverage Coverage
        {
            get { return _coverage; }
            
        }


        //ObservableCollection<FeatureObject> _features;

        //public ObservableCollection<FeatureObject> Features
        //{
        //    get { return _features; }
        //    set { _features = value; }
        //}

        ObservableCollection<PCFeatureObject> _features;

        public ObservableCollection<PCFeatureObject> Features
        {
            get { return _features; }
            set { _features = value; }
        }


        List<MAPSCType> _ptBCTypes;

        public List<MAPSCType> PtBCTypes
        {
            get { return _ptBCTypes; }
            set { _ptBCTypes = value; }
        }



        List<MAPSCType> _lnBCTypes;

        public List<MAPSCType> LnBCTypes
        {
            get { return _lnBCTypes; }
            set { _lnBCTypes = value; }
        }


        List<MAPSCType> _ndBCTypes;

        public List<MAPSCType> NdBCTypes
        {
            get { return _ndBCTypes; }
            set { _ndBCTypes = value; }
        }


        List<MAPSCType> _polyBCTypes;

        public List<MAPSCType> PolyBCTypes
        {
            get { return _polyBCTypes; }
            set { _polyBCTypes = value; }
        }








        MAPSCType _currentFilterBCType=MAPSCType.NONE;

        public MAPSCType CurrentFilterBCType
        {
            get { return _currentFilterBCType; }
            set { _currentFilterBCType = value; }
        }
     


        public List<MAPSCType> CurrentAllBCTypes
        {
            get {

                switch (this._currentFOType)
                {
                    case FeatureObjectType.POINT:

                        return this._ptBCTypes;

                       
                    case FeatureObjectType.LINE:

                        return this._lnBCTypes;

                       
                    case FeatureObjectType.POLYGON:


                        return this._polyBCTypes;

                       
                    case FeatureObjectType.LINEGROUP:

                        return this._lnBCTypes;
                        
                    default:
                        break;
                }
                
                
                return null; 
            
            }
           
        }


        FeatureObjectType _currentFOType=FeatureObjectType.POINT;

        public FeatureObjectType CurrentFOType
        {
            get { return _currentFOType; }
            set {
                
                _currentFOType = value;

                this.OnPropertyChanged("CurrentFOType");
            
            }
        }




        List<FeatureObjectType> _allFOTypes;

        public List<FeatureObjectType> AllFOTypes
        {
            get { return _allFOTypes; }
            set { _allFOTypes = value; }
        }






        bool _isShowLayerRange;

        public bool IsShowLayerRange
        {
            get { return this._isShowLayerRange; }

        }









        #region 公共函数



        private List<FeatureObject> _newFeatureObjects;

        public List<FeatureObject> NewFeatureObjects
        {
            get { return _newFeatureObjects; }
          

        }



        public void Confirm()
        {
            this._newFeatureObjects = new List<FeatureObject>();

            foreach (PCFeatureObject item in this._features)
            {

                this._newFeatureObjects.Add(item.FeatureObject);
                

            }




 
        }


        #endregion



    }

    public class PCFeatureObject
    {

        public PCFeatureObject(FeatureObject fo,PCCoverageAtrributeTable parent)
        {
            this._featureObject = fo;

            this._parent = parent;

            
 
        }



        #region 公共属性



        public bool IsPolygon
        {
            get {

                if (_featureObject is PolygonFO)
                {
                    return true;

                }
                else
                {
                    return false;
                }
            
            }
        }


        public bool IsPoint
        {
            get
            {

                if (_featureObject is PointFO)
                {
                    return true;

                }
                else
                {
                    return false;
                }

            }
        }


        public bool IsLine
        {
            get
            {

                if (_featureObject is LineFO)
                {
                    return true;

                }
                else
                {
                    return false;
                }

            }
        }




        FeatureObject _featureObject;

        public FeatureObject FeatureObject
        {
            get { return _featureObject; }
            set { _featureObject = value; }
        }


        PCCoverageAtrributeTable _parent;

        public PCCoverageAtrributeTable Parent
        {
            get { return _parent; }
            set { _parent = value; }
        }


     

        public List<MAPSCType> AvailableSCType
        {
            get {

                if (this._featureObject is PointFO)
                {
                    return this._parent.PtBCTypes;
                    
                }

                if (this._featureObject is LineFO)
                {
                    return this._parent.LnBCTypes;
                    
                }

                if (this._featureObject is PolygonFO)
                {
                    return this._parent.PolyBCTypes;
                    
                }

                if (this._featureObject is NodeFO)
                {
                    return this._parent.NdBCTypes;
                    
                }

                return null; 
            
            
            }
           
        }
    

       



        #endregion

    
    }
}
